using Assets.Scripts.Map.Room;
using Assets.Scripts.System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Search;
using UnityEngine;

public class MapSystem : MonoSingleton<MapSystem>, IBaseSystem
{
    public bool isOpen = false;
    public string curPlayerRoomID = "";
    RoomFirstDungeonGenerator roomFirstDungeonGenerator;
    DungeonManager dungeonManager;

    public Vector2Int GenerateMap()
    {
        roomFirstDungeonGenerator.GenerateDungeon();
        return dungeonManager.RoomsTypeDict[RoomType.ROOM_START][0].RoomCenterPos;
    }
    public BaseRoom GetCurRoom()
    {
        if(curPlayerRoomID != null)
        {
            return dungeonManager.Rooms.Find(x => x.RoomID == curPlayerRoomID);
        }
        return null;
    }
    public void Open()
    {
        roomFirstDungeonGenerator = transform.Find("/Map/Generator")?.GetComponent<RoomFirstDungeonGenerator>();
        dungeonManager = transform.Find("/Map/Generator")?.GetComponent<DungeonManager>();
        isOpen = true;
    }
    public void Close()
    {
        isOpen = false;
        roomFirstDungeonGenerator.ResetAll();
    }

    public void OnUpdate()
    {
        foreach (var room in dungeonManager.Rooms)
        {
            room.CheckPlayerEnterOrExitRoom();
        }
    }


}
